<?php

declare(strict_types=1);

namespace App\Common\AsyncQueue;

use Hyperf\AsyncQueue\JobInterface;
use Hyperf\AsyncQueue\MessageInterface;

class JobMessage implements MessageInterface
{
    protected int $attempts = 0;

    public function __construct(protected JobInterface $job)
    {
    }

    public function job(): JobInterface
    {
        return $this->job;
    }

    public function attempts(): bool
    {
        if ($this->job->getMaxAttempts() > $this->attempts++) {
            return true;
        }
        return false;
    }

    public function getAttempts(): int
    {
        return $this->attempts;
    }

}